package com.example.ssm.动态代理.one;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class Main {

    public static void main(String[] args) {

        System.getProperties().setProperty("sun.misc.ProxyGenerator.saveGeneratedFiles","true");

        HelloInterface hello = new Hello();
        ByeInterface bye = new Bye();

        InvocationHandler handler = new ProxyHandler(hello);
        InvocationHandler byeHandler = new ProxyHandler(bye);

        HelloInterface proxyHello =
                (HelloInterface)Proxy.newProxyInstance(hello.getClass().getClassLoader(),hello.getClass().getInterfaces(),handler);
        ByeInterface byeInterface =
                (ByeInterface) Proxy.newProxyInstance(bye.getClass().getClassLoader(),bye.getClass().getInterfaces(),byeHandler);

        proxyHello.sayHello();
        byeInterface.sayBye(".");
    }
}
